package com.csj.lc.controller;

import com.csj.lc.base.BaseController;
import com.csj.lc.entity.dto.LayuiDTO;
import com.csj.lc.entity.dto.ReturnDTO;
import com.csj.lc.entity.User;
import com.csj.lc.entity.dto.SearchDTO;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

@Controller
@RequestMapping("/user/")
public class UserController extends BaseController {

    @RequestMapping("test")
    public User getUser(int userId){

        return userService.getUserById( userId);
    }


    @RequestMapping("detail")
    public String detail(HttpServletRequest request, Model model){

        return userService.detail(request,model);
    }

    @RequestMapping("history")
    public String history(HttpServletRequest request, Model model,
                          SearchDTO searchDTO,@RequestParam(name="isDefault",defaultValue = "false")Boolean isDefault
    ){
        return userService.history( request , model , searchDTO ,isDefault);
    }

    @RequestMapping("/adminList")
    public String adminList(HttpServletRequest request, Model model,
                       @RequestParam(name="pageNo",required=false,defaultValue = "1") int pageNo){

        return userService.list(request,model,1,pageNo);
    }

    @RequestMapping("/bossList")
    public String bossList(HttpServletRequest request, Model model,
                       @RequestParam(name="pageNo",required=false,defaultValue = "1") int pageNo){

        return userService.list(request,model,2,pageNo);
    }

    @RequestMapping("/employeeList")
    public String employeeList(HttpServletRequest request, Model model,
                       @RequestParam(name="pageNo",required=false,defaultValue = "1") int pageNo){

        return userService.list(request,model,3,pageNo);
    }

    @RequestMapping("/getUserList")
    @ResponseBody
    public LayuiDTO<User> getBossList(HttpServletRequest request, Model model,
                                      @RequestParam(name="roleId",required=true)int roleId,
                                      @RequestParam(name="page",defaultValue ="1",required = false) int pageNo ,
                                      @RequestParam(name="limit",defaultValue ="10",required = false)int pageSize){

        return userService.getUserList(request,model,roleId,pageNo,pageSize) ;
    }

    @RequestMapping("update")
    @ResponseBody
    public ReturnDTO<User> update(HttpServletRequest request, User user){

        return userService.update(request,user);
    }

    @RequestMapping("password")
    public String password(HttpServletRequest request, Model model){

        return userService.password(request,model);
    }

    @RequestMapping("changePassword")
    @ResponseBody
    public ReturnDTO<User> changePassword(HttpServletRequest request, User user){

        return userService.changePassword(request,user);
    }

}

